package com.hengtongxing.hejiayun.steward;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gyf.immersionbar.ImmersionBar;
import com.hengtongxing.hejiayun.R;
import com.hengtongxing.hejiayun.base.BaseFragment;
import com.hengtongxing.hejiayun.base.DataCallBack;
import com.hengtongxing.hejiayun.bean.GoodsListBean;
import com.hengtongxing.hejiayun.bean.MenuListBean;
import com.hengtongxing.hejiayun.homepage.CleanServiceActivity;
import com.hengtongxing.hejiayun.homepage.ConsultServiceActivity;
import com.hengtongxing.hejiayun.homepage.PayFeeActivity;
import com.hengtongxing.hejiayun.homepage.RepairsServiceActivity;
import com.hengtongxing.hejiayun.homepage.adapter.HomeMenuListAdapter;
import com.hengtongxing.hejiayun.homepage.model.HomePageModelImpl;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 管家
 */
public class StewradFragment extends BaseFragment {

    @BindView(R.id.recyclerView_menu)
    RecyclerView recyclerViewMenu;
    @BindView(R.id.ll_repairs)
    LinearLayout llRepairs;
    @BindView(R.id.ll_consult)
    LinearLayout llConsult;
    @BindView(R.id.ll_clean)
    LinearLayout llClean;
    @BindView(R.id.ll_fees)
    LinearLayout llFees;
    private HomeMenuListAdapter menuListAdapter;
    private List<MenuListBean.DataBean> menuBeanList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_stewrad, container, false);
        ButterKnife.bind(this, view);
        initView();
        requestAppMenu();
        return view;
    }

    @Override
    public void initImmersionBar() {
        //黑
        ImmersionBar.with(this)
                .statusBarDarkFont(true)
                .navigationBarDarkIcon(true)
                .navigationBarColor(R.color.white)
                .statusBarDarkFont(true, 0.2f)
                .init();
    }

    public void initView() {
        menuBeanList = new ArrayList<>();
        menuListAdapter = new HomeMenuListAdapter(menuBeanList);
        recyclerViewMenu.setNestedScrollingEnabled(false);
        recyclerViewMenu.setLayoutManager(new GridLayoutManager(mActivity, 4));
        recyclerViewMenu.setAdapter(menuListAdapter);
        menuListAdapter.setOnCallBackListener(position -> {
            MenuListBean.DataBean dataBean = menuBeanList.get(position);
            if ("HousesRepair".equals(dataBean.getPath())) {
                skipToActivity(RepairsServiceActivity.class);
            }
            if ("Advisory".equals(dataBean.getPath())) {
                skipToActivity(ConsultServiceActivity.class);
            }
            if ("Housekeeping".equals(dataBean.getPath())) {
                skipToActivity(CleanServiceActivity.class);
            }
            if ("PropertyCosts".equals(dataBean.getPath())) {
                skipToActivity(PayFeeActivity.class);
            }
        });
    }

    public void requestAppMenu() {
        new HomePageModelImpl().requestAppMenu("3", new DataCallBack<MenuListBean>() {
            @Override
            public void onSuccessful(MenuListBean bean) {
                menuBeanList.clear();
                if (bean.getData() != null && bean.getData().size() > 0) {
                    menuBeanList.addAll(bean.getData());
                }
                menuListAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }
}
